﻿using System;
using System.Xml.Serialization;
using System.Web.Script.Serialization;
using Fuse8.ContentManagementFramework.SystemFacade;
using Fuse8.DomainFramework.Domain;
using Fuse8.DomainFramework.BusinessService;
using Fuse8.DomainFramework.CacheService;

namespace Fuse8.ContentManagementFramework.Domain
{
    [Serializable]
    public partial class CmsContent : CmsLocalizedEntityObject
    {
        #region Linked fields

        private CmsContentType _contentType;

        #endregion

        #region Properties

        public virtual int ContentTypeId { get; set; }

        public virtual string ContentTitle { get; set; }

        public virtual string ContentSummary { get; set; }

        public virtual string ContentBody { get; set; }

        public virtual string ContentCode { get; set; }

        public int PublicContentId { get; set; }

        public override bool UseBuiltInFlow
        {
            get { return false; }
        }

        #endregion

        #region Linked properties

        [XmlIgnore]
        [ScriptIgnore]
        public CmsContentType ContentType
        {
            get
            {
                if (_contentType == null)
                {
                    var businessFacade = new BusinessServiceFacade<CmsContentType, int>();
                    if (businessFacade != null)
                    {
                        _contentType = businessFacade.FindOne(ContentTypeId);
                    }
                }

                return _contentType;
            }
            set
            {
                ContentTypeId = value != null ? value.Id : 0;

                _contentType = value;
            }
        }

        #endregion

        #region Constructor

        public CmsContent()
        { }

        #endregion

        #region EntityObject override

        public override string TypeParameter
        {
            get
            {
                return CmsConstants.ContentParameter + ContentTypeId;
            }
        }        

        #endregion
    }
}
